import { del, down, get, post, put } from "@/common/http";
import { ITableWrap } from "@/types/common";
import { IEmployee, TAddAndModuleEmployee } from "@/types/employee";
import {
  IResetPassword,
  IRetrievePassword,
  LoginForm,
  LoginRes,
} from "../types/login";

/**
 *
 * @param data
 * @returns 登陆
 */
export const login = (data: LoginForm) =>
  post<LoginRes>("/api/v1/employee/login", data);

/**
 *
 * @param data
 * @returns 重置密码
 */
export const resetPassword = (data: IResetPassword) =>
  post<boolean>("/api/v1/employee/resetPassword", data);

/**
 *
 * @param data
 * @returns 发送验证码
 */
export const sendSMS = (data: Pick<IRetrievePassword, "phone" | "code">) =>
  post<boolean>("/api/v1/employee/sendSMS", data);

/**
 *
 * @param data
 * @returns 找回密码
 */
export const retrievePassword = (data: IRetrievePassword) =>
  post<boolean>("/api/v1/employee/retrievePassword", data);

/**
 *
 * @param page 页数 从1开始
 * @param pageSize 每页条数
 * @param name 用户名
 * @returns 员工分页
 */
export const employeePage = (page: number, pageSize: number, name?: string) =>
  get<ITableWrap<IEmployee>>("/api/v1/employee/page", {
    params: {
      page,
      pageSize,
      name,
    },
  });

/**
 *
 * @returns 导出excel
 */
export const exportExcel = () =>
  down("/api/v1/employee/export", {
    responseType: "blob",
  });

/**
 *
 * @param data
 * @returns 创建员工
 */
export const employeeCreate = (data: TAddAndModuleEmployee) =>
  post<IEmployee>("/api/v1/employee", data);

/**
 *
 * @param id
 * @returns 根据id查询
 */
export const employeeGetOne = (id: string) =>
  get<IEmployee>("/api/v1/employee/" + id);

/**
 *
 * @param id
 * @returns 根据状态查询
 */
export const employeeGetEnable = (status: number) =>
  get<IEmployee[]>("/api/v1/employee/enable", {
    params: {
      status,
    },
  });

/**
 *
 * @param data
 * @returns 更新
 */
export const employeeUpdate = (data: TAddAndModuleEmployee) =>
  put<boolean>("/api/v1/employee", data);

/**
 *
 * @param params
 * @returns 删除
 */
export const employeeDel = (ids: string) =>
  del<boolean>("/api/v1/employee", {
    params: { ids },
  });

/**
 *
 * @param data
 * @returns 更新
 */
export const employeeSetStatus = (status: number, ids: string) =>
  post<boolean>(
    "/api/v1/employee/status/" + status,
    {},
    {
      params: {
        ids,
      },
    }
  );
